package com.lajiaomian.springbootruijiwaimai.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lajiaomian.springbootruijiwaimai.common.BaseContext;
import com.lajiaomian.springbootruijiwaimai.common.R;
import com.lajiaomian.springbootruijiwaimai.pojo.Orders;
import com.lajiaomian.springbootruijiwaimai.service.impl.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author lajiaomian
 * @create 2022-08-15-21:27
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 分页展示订单
     * @param page
     * @param pageSize
     * @param number
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/page")
    public R<Page<Orders>> PageList(Integer page, Integer pageSize, String number,String beginTime,String endTime){
        log.info("Order的分页展示：{},{},{},{},{}",page,pageSize,number,beginTime,endTime);
        Page<Orders> pageInfo = ordersService.getPage(page, pageSize, number, beginTime, endTime);
        return R.success(pageInfo);
    }

    /**
     * 用户页分页
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page<Orders>> UserPage(Integer page,Integer pageSize){
        log.info("用户分页...{}{}",page,pageSize);
        Page<Orders> pageInfo = ordersService.getUserPage(page, pageSize, BaseContext.getCurrId());
        return R.success(pageInfo);
    }

    /**
     * 提交订单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        log.info("提交订单：{}",orders);
        ordersService.submit(orders);
        return R.success("提交订单成功");
    }
}
